#include<bits/stdc++.h>
using namespace std;
 
#define lsn (u << 1)
#define rsn (u << 1 | 1)
#define mid (l + r >> 1)
 
typedef long long ll;
typedef unsigned long long ull;
 
typedef pair<int, int> P;
 
const int MAXN = 100 + 10;
const int MAX_LEN = 1e5 + 10;
const int MAX_LOG_V = 22;
const ll INF = 1e17;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const ull B = 100000007; 


int n, k;
int a[MAXN], b[MAXN];
int dp1[MAX_LEN], dp2[MAX_LEN];

int a1[MAXN], a2[MAXN];
int b1[MAXN], b2[MAXN]; 

void solve() {
	scanf("%d %d", &amp;n, &amp;k);
	for(int i = 1; i <= n; i++) scanf("%d", &amp;a[i]);
	for(int i = 1; i <= n; i++) scanf("%d", &amp;b[i]);

	int tot1 = 0, tot2 = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i]-k*b[i] >= 0) {
			a1[++tot1] = a[i];
			b1[tot1] = a[i]-k*b[i];
		}
		else {
			a2[++tot2] = a[i];
			b2[tot2] = -(a[i]-k*b[i]);
		}
	}
	for(int i = 1; i <= tot1; i++) {
		for(int j = MAX_LEN - 1; j >= b1[i]; j--) {
			if(j-b1[i] == 0 || dp1[j-b1[i]])
				dp1[j] = max(dp1[j], dp1[j-b1[i]]+a1[i]);
		}
	}
	for(int i = 1; i <= tot2; i++) {
		for(int j = MAX_LEN - 1; j >= b2[i]; j--) {
			if(j-b2[i] == 0 || dp2[j-b2[i]])
				dp2[j] = max(dp2[j], dp2[j-b2[i]]+a2[i]);
		}
	}
	int ans = dp1[0];
	for(int i = 1; i <= 1e5; i++) {
		if(dp1[i] &amp;&amp; dp2[i]) ans = max(ans, dp1[i]+dp2[i]);
	}
	if(ans == 0) puts("-1");
	else printf("%d\n", ans);
}
 
 
int main() {
	freopen("lock.in","r",stdin);
    freopen("lock.out","w",stdout);
	//ios::sync_with_stdio(false);
	int t = 1; //scanf("%d", &amp;t);
	while(t--) {
		solve();
	}
	return 0;
}



